Package cpsc2150.extendedConnectX.models
Class GameBoard
java.lang.Object
cpsc2150.extendedConnectX.models.AbsGameBoard
cpsc2150.extendedConnectX.models.GameBoard
- All Implemented Interfaces:
IGameBoard
Class that represents an entire game board for the ExtendedConnectX game using an
array.
This class includes methods to place tokens, check token locations, and determine whether or not the game has been won or is over.
- Invariant:
- (board[][] = ' ' OR board[][] = [ a player token ]) AND
[ there are no gaps between non-space tokens ] AND
MIN_ROWS
<=numRows<MAX_ROWS AND MIN_COLUMNS<=numColumns<MAX_COLUMNS MIN_NUM_TO_WIN<=numToWin<=MAX_NUM_TO_WIN
-
Field Summary
Fields inherited from interface cpsc2150.extendedConnectX.models.IGameBoard
MAX_COLUMNS, MAX_NUM_TO_WIN, MAX_ROWS, MIN_COLUMNS, MIN_NUM_TO_WIN, MIN_ROWS -
Constructor Summary
ConstructorsConstructorDescriptionGameBoard(int rows, int columns, int win) Constructor for GameBoard that takes parameters for the number of rows, the number of columns, and the number needed to win, and initializes all indexes of board to ' '. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of columns in the GameBoard.intReturns the number of rows in the GameBoard.intReturns the number of tokens in a row needed to win the game.voidplaceToken(char p, int c) Function that places the character p in column c.charwhatsAtPos(BoardPosition pos) Function that returns what is in the GameBoard at position pos.Methods inherited from class cpsc2150.extendedConnectX.models.AbsGameBoard
toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface cpsc2150.extendedConnectX.models.IGameBoard
checkDiagWin, checkForWin, checkHorizWin, checkIfFree, checkTie, checkVertWin, isPlayerAtPos
-
Constructor Details
-
GameBoard
public GameBoard(int rows, int columns, int win) Constructor for GameBoard that takes parameters for the number of rows, the number of columns, and the number needed to win, and initializes all indexes of board to ' '.- Parameters:
rows- Number of rowscolumns- Number of columnswin- Number needed to win- Pre:
- MIN_ROWS
<=rows<MAX_ROWS AND MIN_COLUMNS<=columns<MAX_COLUMNS AND MIN_NUM_TO_WIN<=win<=MAX_NUM_TO_WIN AND win<=rows AND win<=columns - Post:
- board[][] = ' ' AND numRows = rows AND numColumns = columns AND numToWin = win AND [ size of board[] ] = numRows AND [ size of board[][] ] = numColumns
-
-
Method Details
-
placeToken
public void placeToken(char p, int c) Description copied from interface:IGameBoardFunction that places the character p in column c. The token will be placed in the lowest available row in column c.- Specified by:
placeTokenin interfaceIGameBoard- Parameters:
p- Character to be placed (representing player token)c- Column to place token in
-
whatsAtPos
Description copied from interface:IGameBoardFunction that returns what is in the GameBoard at position pos. If no marker is there, it returns a blank space char.- Specified by:
whatsAtPosin interfaceIGameBoard- Parameters:
pos- BoardPosition pair of row and column- Returns:
- Character representing player token or space
-
getNumRows
public int getNumRows()Description copied from interface:IGameBoardReturns the number of rows in the GameBoard.- Specified by:
getNumRowsin interfaceIGameBoard- Returns:
- The number of rows
-
getNumColumns
public int getNumColumns()Description copied from interface:IGameBoardReturns the number of columns in the GameBoard.- Specified by:
getNumColumnsin interfaceIGameBoard- Returns:
- The number of columns
-
getNumToWin
public int getNumToWin()Description copied from interface:IGameBoardReturns the number of tokens in a row needed to win the game.- Specified by:
getNumToWinin interfaceIGameBoard- Returns:
- The number of tokens
-